<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/resources/css/public.css" media="all" />
	<style>

	</style>
</head>
<body class="childrenBody">
<form class="layui-form layui-row changePwd" method="post" id="formChange" lay-filter="formChange">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" value="" id="name" th:value="${session.user.name}" disabled  class="layui-input layui-disabled" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item" >
			<label class="layui-form-label">邮箱</label>
			<div class="layui-input-block" >
				<input type="text" style="width:75%;float: left" value="" th:value="${session.user.email}"id="email" lay-verify="email" disabled class="layui-input userEmail">
				<button style="width:25%; height:38px;" class="layui-input" type="button" onclick="sendEmail()">发送验证码</button>
			</div>
		</div>
		<div class="layui-form-item" >
			<label class="layui-form-label">验证码</label>
			<div class="layui-input-block" >
				<input type="text" value=""placeholder="输入验证码" id="code" lay-verify="required" class="layui-input usercode">
			</div>
		</div>
		<!--<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="oldPassword" placeholder="请输入旧密码" lay-verify="required" class="layui-input pwd" autocomplete="false">
			</div>
		</div>-->

		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdOne" placeholder="请输入新密码" lay-verify="required|newPwd"  class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdTwo" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/page/user/user.js"></script>
<script type="text/javascript">
	function sendEmail() {
		var form = layui.form;
		var layer = layui.layer;
		var $ = layui.jquery;
		var index = layer.msg('发送中，请稍候',{icon: 16,time:false,shade:0.8});

		var email = $("#email");
		$.ajax({
			url: "/user/sendEmail"
			, data: {"email": email.val()}
			, type: "post"
			, success: function (res) {
				setTimeout(function(){
					layer.close(index);
					layer.msg("发送成功！");
					$('#email').attr("disabled",false);
				},2000);
			}
		})
	}
</script>
<script type="text/javascript">
	layui.use(['jquery','form','layer'],function () {
		var $ = layui.jquery;
		var form = layui.form;
		var layer = layui.layer;


		form.on("submit(changePwd)",function () {
		    var name = $("#name").val();
			var code = $("#code").val();
            // var oldPassword = $("#oldPassword").val();
            var newPwdOne = $("#newPwdOne").val();
            var newPwdTwo = $("#newPwdTwo").val();
			if (newPwdOne.valueOf()!=newPwdTwo.valueOf()) {
				layer.msg("两次密码不一致");
				return false;
			}
            layer.confirm('你确定要修改【' + name + '】这个用户的密码？', {icon: 3, title: '提示'}, function (index) {
				$.post('/user/changePassword',{code:code,newPwdOne:newPwdOne,newPwdTwo:newPwdTwo},function (res) {
					layer.msg(res.msg);
				});
				layer.close(index);

            });
        	return false;
		});



    });
</script>

</body>
</html>